Attribute VB_Name = "bookmarks"
Option Explicit
Public Sub BookmarkAdd()

  Dim a As String, b As String

  a$ = InputBox$("what address do you want to make a bookmark for?", "add bookmark", frmMemoryEditor.Text1.Text) 'gets the addy
  If a$ = "" Then Exit Sub 'checks if blank

  If left$(a$, 1) <> "$" Then a$ = "$" & a$ 'prefixes the addy
  a$ = "$" & fixaddress(Mid$(a$, 2))
  a$ = UCase(a$) 'uppercases

  b$ = InputBox$("what bookmark text do you want displayed along with the bookmarked address?", "add bookmark") 'gets the bookmark text
  If b$ = "" Then Exit Sub 'checks if blank

  Call frmMemoryEditor.lstBookmarks.AddItem(a$ & " - " & b$) 'adds it

  Call BookmarksSave 'saves them

End Sub
Public Sub BookmarkEdit()

  Dim a As String, b As String

  a$ = InputBox$("what address do you want to make a bookmark for?", "add bookmark", left$(frmMemoryEditor.lstBookmarks.Text, 5)) 'gets the addy
  If a$ = "" Then Exit Sub 'checks if blank

  If left$(a$, 1) <> "$" Then a$ = "$" & a$ 'prefixes the addy
  a$ = "$" & fixaddress(Mid$(a$, 2))
  a$ = UCase(a$) 'uppercases

  b$ = InputBox$("what bookmark text do you want displayed along with the bookmarked address?", "add bookmark", Mid$(frmMemoryEditor.lstBookmarks.Text, 9)) 'gets the bookmark text
  If b$ = "" Then Exit Sub 'checks if blank

  Call frmMemoryEditor.lstBookmarks.RemoveItem(frmMemoryEditor.lstBookmarks.ListIndex) 'remove old
  Call frmMemoryEditor.lstBookmarks.AddItem(a$ & " - " & b$) 'adds it

  Call BookmarksSave 'saves them

End Sub


Public Sub BookmarkRemove()

  Call frmMemoryEditor.lstBookmarks.RemoveItem(frmMemoryEditor.lstBookmarks.ListIndex) 'removes list item

  Call BookmarksSave 'saves bookmarks

End Sub
Public Sub BookmarksClear()

  Call frmMemoryEditor.lstBookmarks.Clear 'clears list

  Call BookmarksSave 'saves list

End Sub

Public Sub BookmarksSave()

  Dim SaveList As Long

  On Error Resume Next

  If ROM_Name$ = "" Then Exit Sub 'checks to see if a rom is loaded

  If frmMemoryEditor.lstBookmarks.ListCount = 0 And fileexists(App.Path & "\folders\bookmarks\" & ROM_Name$ & ".vbm") Then 'checks if there's no bookmarks and if the file exists
    Call Kill(App.Path & "\folders\bookmarks\" & ROM_Name$ & ".vbm") 'deletes file
    Exit Sub
  End If

  If frmMemoryEditor.lstBookmarks.ListCount = 0 Then Exit Sub 'checks if there are any bookmarks

  Open App.Path & "\folders\bookmarks\" & ROM_Name$ & ".vbm" For Output As #1 'opens the file

  For SaveList& = 0 To frmMemoryEditor.lstBookmarks.ListCount - 1 'sorts through bookmarks
    Print #1, Replace(frmMemoryEditor.lstBookmarks.List(SaveList&), ",", "$COMMA$") 'saves them
  Next SaveList&

  Close #1

End Sub
Public Sub BookmarksLoad()

  Dim MyString As String

  On Error Resume Next

  Call frmMemoryEditor.lstBookmarks.Clear 'clear

  If Not fileexists(App.Path & "\folders\bookmarks\" & ROM_Name$ & ".vbm") Then Exit Sub 'checks if bookmarks exist

  Open App.Path & "\folders\bookmarks\" & ROM_Name$ & ".vbm" For Input As #1 'opens file

  While Not EOF(1) 'sorts through entire file
    Input #1, MyString$ 'gets text
    DoEvents 'cpu shit
    Call frmMemoryEditor.lstBookmarks.AddItem(Replace(MyString$, "$COMMA$", ",")) 'adds it
  Wend

  Close #1

End Sub
